#include "Settings.h"
#include "File.h"

namespace Settings{

    //anonymous namespace so you can't call Settings::InitNumDataDataBlocks()
    namespace{
        unsigned int InitNumDataBlocks(){
            
            unsigned int inodes_space;
            unsigned int rem_space;
            unsigned int num_data_blocks;
            unsigned int addys_per_block;

            inodes_space = NumInodes*sizeof(Inode);

            rem_space = DiskSize - inodes_space;

            /*
               The superblock contains a char for each data block.
               Calculate the number of data blocks we can have:

               space for superblock + data space <= remaining space
               num_data_blocks + num_data_blocks*blocksize <= remaining space
               num_data_blocks(1+blocksize) <= remaining_space
               num_data_blocks = floor(remaining_space/(1+blocksize))
             */
            num_data_blocks = rem_space/(1+BlockSize);

            addys_per_block  = BlockSize/sizeof(unsigned int);
            printf("FS setup info:\n");
            printf("\tDiskSize: %0.2f MB\n",(float)DiskSize/(1024*1024));
            printf("\tBlockSize: %0.2f KB\n",(float)BlockSize/(1024));
            printf("\tNumInodes: %u\n",NumInodes);
            printf("\tsizeof(Inode): %u bytes\n",(unsigned int)sizeof(Inode));
            printf("\tNumber of direct, indirect, doubly indirect ptrs: %u, %u, %u\n",InodeNumDirPtrs,InodeNumIndir1Ptrs,InodeNumIndir2Ptrs);
            printf("\tSpace accessible from ptrs: %0.2f MB\n",(float)(InodeNumDirPtrs*BlockSize+addys_per_block*InodeNumIndir1Ptrs*BlockSize+InodeNumIndir2Ptrs*addys_per_block*addys_per_block*BlockSize)/(1024*1024));
            printf("\tMax filename length: %u\n",MaxNameLength);
            printf("\tNumDataBlocks: %u (%0.2f MB)\n",num_data_blocks,(float)(num_data_blocks*BlockSize)/(1024*1024));

            return num_data_blocks;

        };
    };

    const unsigned int NumDataBlocks = InitNumDataBlocks();

};

